package com.siam.package_merchant.feign;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.siam.package_common.entity.BasicResult;
import com.siam.package_merchant.entity.MerchantBillingRecord;
import com.siam.package_merchant.model.param.MerchantBillingRecordParam;
import com.siam.package_merchant.service.MerchantBillingRecordService;
import com.siam.package_user.model.param.MemberBillingRecordParam;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 提供给其他服务Feign客户端调用的用户模块相关接口
 */
@RestController
public class MerchantBillingRecordFeignProvider implements MerchantBillingRecordFeignApi {

    @Autowired
    private MerchantBillingRecordService merchantBillingRecordService;

    public BasicResult insertSelective(MerchantBillingRecord record){
        merchantBillingRecordService.insertSelective(record);
        return BasicResult.success();
    }

    public BasicResult selectByPrimaryKey(@RequestParam("id") Integer id){
        return BasicResult.success(merchantBillingRecordService.selectByPrimaryKey(id));
    }

    public BasicResult updateByPrimaryKeySelective(MerchantBillingRecord record){
        merchantBillingRecordService.updateByPrimaryKeySelective(record);
        return BasicResult.success();
    }

    @Override
    public BasicResult<List<MerchantBillingRecord>> list(MerchantBillingRecordParam param) {
        LambdaQueryWrapper<MerchantBillingRecord> queryWrapper = new LambdaQueryWrapper<>();
        if(param.getType() != null){
            queryWrapper.eq(MerchantBillingRecord::getType, param.getType());
        }
        if(CollectionUtils.isNotEmpty(param.getTypeList())){
            queryWrapper.in(MerchantBillingRecord::getType, param.getTypeList());
        }
        if(param.getCoinType() != null){
            queryWrapper.eq(MerchantBillingRecord::getCoinType, param.getCoinType());
        }
        if(param.getOrderId() != null){
            queryWrapper.eq(MerchantBillingRecord::getOrderId, param.getOrderId());
        }
        return BasicResult.success(merchantBillingRecordService.list(queryWrapper));
    }
}